package com.example.api.config;

import com.example.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {
@Bean
    public RequestInterceptor UserInfoRequestInterceptor(){
    return new RequestInterceptor() {
        @Override
        public void apply(RequestTemplate requestTemplate) {
            //微服务之间传递携带用户信息
            if (UserContext.getUser()!=null){
                requestTemplate.header("user-info", UserContext.getUser());
            }

        }
    };
}
}
